﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:WPFDataEditors.Calculator.Control">
    <ContextMenu x:Key="calculatorContextMenu">
        <MenuItem Header="Copy" Command="{Binding CopyCommand}"/>
        <MenuItem Header="Paste" Command="{Binding PasteCommand}"/>
    </ContextMenu>
    <LinearGradientBrush x:Key="ClearBrush" StartPoint="0.5,0.0" EndPoint="0.5,1.0">
        <GradientStop Color="#FCB3B3" Offset="1"/>
        <GradientStop Color="#F49B9A" Offset="0.5" />
    </LinearGradientBrush>
    <SolidColorBrush x:Key="ClearForeground" Color="#BF5253"/>
    <LinearGradientBrush x:Key="OperatorBrush" StartPoint="0.5,0.0" EndPoint="0.5,1.0">
        <GradientStop Color="#ECF0F6" Offset="1"/>
        <GradientStop Color="#D5DBE3" Offset="0.5" />
    </LinearGradientBrush>
    <DrawingBrush x:Key="Arrow30" Stretch="Uniform">
        <DrawingBrush.Drawing>
            <DrawingGroup>
                <DrawingGroup.Children>
                    <GeometryDrawing Brush="#FF000000" Geometry="F1 M 204.794,418.073L 192.688,405.968L 192.688,414.385L 150.684,414.385L 150.684,421.761L 192.688,421.761L 192.688,430.178L 204.794,418.073 Z "/>
                </DrawingGroup.Children>
            </DrawingGroup>
        </DrawingBrush.Drawing>
    </DrawingBrush>
    <ControlTemplate x:Key="CalculatorButtonPanel" TargetType="{x:Type ContentControl}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="3" />
                <ColumnDefinition />
                <ColumnDefinition Width="3" />
                <ColumnDefinition />
                <ColumnDefinition Width="3" />
                <ColumnDefinition />
                <ColumnDefinition Width="3" />
                <ColumnDefinition />
                <ColumnDefinition Width="3" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="3" />
                <RowDefinition />
                <RowDefinition Height="3" />
                <RowDefinition />
                <RowDefinition Height="3" />
                <RowDefinition />
                <RowDefinition Height="3" />
                <RowDefinition />
                <RowDefinition Height="3" />
                <RowDefinition />
                <RowDefinition Height="3" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Button Grid.Row="0" Grid.Column="0" MinWidth="28" MinHeight="26"  Background="{StaticResource OperatorBrush}" Tag="MC" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">MC</Button>
            <Button Grid.Row="0" Grid.Column="2" MinWidth="28" MinHeight="26"  Background="{StaticResource OperatorBrush}" Tag="MR" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">MR</Button>
            <Button Grid.Row="0" Grid.Column="4" MinWidth="28" MinHeight="26"  Background="{StaticResource OperatorBrush}" Tag="MS" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">MS</Button>
            <Button Grid.Row="0" Grid.Column="6" MinWidth="28" MinHeight="26"  Background="{StaticResource OperatorBrush}" Tag="M+" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">M+</Button>
            <Button Grid.Row="0" Grid.Column="8" MinWidth="28" MinHeight="26"  Background="{StaticResource OperatorBrush}" Tag="M-" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">M-</Button>
            <Button Grid.Row="2" Grid.Column="0" MinWidth="28" MinHeight="26"  Background="{StaticResource OperatorBrush}" Tag="BackSpace" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">
                <Canvas Background="{StaticResource Arrow30}"  Width="24" Height="22" RenderTransformOrigin="0.5,0.5">
                    <Canvas.RenderTransform>
                        <ScaleTransform  ScaleX="-1"/>
                    </Canvas.RenderTransform>
                </Canvas>
            </Button>
            <Button Grid.Row="2" Grid.Column="2" MinWidth="28" MinHeight="26" FontWeight="Bold"  Foreground="{StaticResource ClearForeground}" Background="{StaticResource ClearBrush}" Tag="CE" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">CE</Button>
            <Button Grid.Row="2" Grid.Column="4" MinWidth="28" MinHeight="26" FontWeight="Bold" Foreground="{StaticResource ClearForeground}" Background="{StaticResource ClearBrush}" Tag="C" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">C</Button>
            <Button Grid.Row="2" Grid.Column="6" MinWidth="28" MinHeight="26" Background="{StaticResource OperatorBrush}" Tag="PlusMinus" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">
                &#177;
            </Button>
            <Button Grid.Row="2" Grid.Column="8" MinWidth="28" MinHeight="26" Background="{StaticResource OperatorBrush}"  Tag="SqrRoot" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">&#8730;</Button>
            <Button Grid.Row="4" Grid.Column="0" MinWidth="28" MinHeight="26" Tag="7" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">7</Button>
            <Button Grid.Row="4" Grid.Column="2" MinWidth="28" MinHeight="26" Tag="8" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">8</Button>
            <Button Grid.Row="4" Grid.Column="4" MinWidth="28" MinHeight="26" Tag="9" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">9</Button>
            <Button Grid.Row="4" Grid.Column="6" MinWidth="28" MinHeight="26" Background="{StaticResource OperatorBrush}"  Tag="/" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">/</Button>
            <Button Grid.Row="4" Grid.Column="8" MinWidth="28" MinHeight="26" Background="{StaticResource OperatorBrush}"  Tag="%" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">%</Button>
            <Button Grid.Row="6" Grid.Column="0" MinWidth="28" MinHeight="26" Tag="4" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">4</Button>
            <Button Grid.Row="6" Grid.Column="2" MinWidth="28" MinHeight="26" Tag="5" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">5</Button>
            <Button Grid.Row="6" Grid.Column="4" MinWidth="28" MinHeight="26" Tag="6" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">6</Button>
            <Button Grid.Row="6" Grid.Column="6" MinWidth="28" MinHeight="26" Background="{StaticResource OperatorBrush}"  Tag="*" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">*</Button>
            <Button Grid.Row="6" Grid.Column="8" MinWidth="28" MinHeight="26" Background="{StaticResource OperatorBrush}"  Tag="1/x" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">1/x</Button>
            <Button Grid.Row="8" Grid.Column="0" MinWidth="28" MinHeight="26" Tag="1" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">1</Button>
            <Button Grid.Row="8" Grid.Column="2" MinWidth="28" MinHeight="26" Tag="2" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">2</Button>
            <Button Grid.Row="8" Grid.Column="4" MinWidth="28" MinHeight="26" Tag="3" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">3</Button>
            <Button Grid.Row="8" Grid.Column="6" MinWidth="28" MinHeight="26" Background="{StaticResource OperatorBrush}"  Tag="-" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">-</Button>
            <Button Grid.Row="8" Grid.Column="8" MinWidth="28" MinHeight="26" Background="{StaticResource OperatorBrush}"  Tag="=" Grid.RowSpan="3" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">=</Button>
            <Button Grid.Row="10" Grid.Column="0" MinWidth="28" MinHeight="26" Tag="0" Grid.ColumnSpan="3" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">0</Button>
            <Button Grid.Row="10" Grid.Column="4" MinWidth="28" MinHeight="26" Background="{StaticResource OperatorBrush}"  Tag="." Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">.</Button>
            <Button Grid.Row="10" Grid.Column="6" MinWidth="28" MinHeight="26" Background="{StaticResource OperatorBrush}" Tag="+" Command="{Binding ClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=Tag}">+</Button>
        </Grid>
    </ControlTemplate>
    <Style TargetType="{x:Type local:Calculator}">
        <Setter Property="Background">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFFAFBFB" Offset="0" />
                    <GradientStop Color="#FFF4F4F4" Offset="1" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="BorderBrush" Value="DarkGray" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:Calculator}">
                    <Border Background="{TemplateBinding Background}" 
                       BorderBrush="{TemplateBinding BorderBrush}"
                       BorderThickness="{TemplateBinding BorderThickness}"
                       CornerRadius="3">
                        <Grid Margin="10">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Border  x:Name="PART_Display" ContextMenu="{StaticResource calculatorContextMenu}" Margin="0,0,0,10" Background="White" BorderBrush="DarkGray" BorderThickness="1">
                                <StackPanel>
                                    <Path Stretch="Fill"
                                     Height="9"
                                     Width="9"
                                     Fill="DarkGray"
                                     Data="F1 M 508.172,390L 506.031,390L 504.612,393.385C 504.174,394.477 503.788,395.533 503.453,396.555L 503.417,396.555C 503.334,395.528 503.206,394.471 503.035,393.385L 502.454,390L 500.301,390L 498.637,399L 500.226,399L 500.807,395.537C 500.903,394.973 501,394.379 501.099,393.756C 501.198,393.133 501.287,392.534 501.367,391.957L 501.402,391.957C 501.444,392.514 501.499,393.08 501.567,393.655C 501.635,394.231 501.712,394.776 501.8,395.292L 502.382,398.871L 503.7,398.871L 505.231,395.233C 505.445,394.724 505.663,394.187 505.884,393.622C 506.105,393.057 506.313,392.502 506.508,391.957L 506.543,391.957C 506.411,393.11 506.304,394.292 506.223,395.502L 505.979,399L 507.637,399L 508.172,390 Z "
                                     HorizontalAlignment="Left"
                                     VerticalAlignment="Top"                                              
                                     Margin="4,4,0,0"
                                     Visibility="{Binding MemoryVisible}" />
                                    <Viewbox Stretch="Uniform" Height="30" HorizontalAlignment="Right" VerticalAlignment="Center">
                                        <TextBlock x:Name="txtDisplayText" Text="{Binding DisplayText,UpdateSourceTrigger=PropertyChanged}" 
                                      HorizontalAlignment="Stretch" FontSize="18" Height="30" TextWrapping="Wrap" 
                                      Margin="0,0,4,0"
                                     />
                                    </Viewbox>
                                </StackPanel>
                            </Border>
                            <ContentControl x:Name="PART_CalculatorButtonPanel" Grid.Row="1" HorizontalAlignment="Center" Width="{Binding ElementName=PART_Display,Path=ActualWidth}" Template="{StaticResource CalculatorButtonPanel}" DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsFocused" Value="True">
                            <Setter TargetName="PART_Display" Property="Background" Value="#E7F5FF" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>